define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'luyoulogs/index' + location.search,
                    add_url: 'luyoulogs/add',
                    edit_url: 'luyoulogs/edit',
                    del_url: 'luyoulogs/del',
                    multi_url: 'luyoulogs/multi',
                    import_url: 'luyoulogs/import',
                    table: 'luyou_logs',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false },
                        {field: 'luyou.name', title: __('设备'), operate: 'LIKE'},
                        {field: 'num', title: __('Num'),operate: false },
                        //{field: 'before', title: __('Before')},
                        //{field: 'after', title: __('After')},
                        {field: 'opt_date', title: __('Opt_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
                //$("#price1").text(data.extend.price1);
                //$("#price2").text(data.extend.price2);
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
